package org.chat.hhdchat.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.chat.hhdchat.repository.ChatMessageRepository;

//初始化处理器链
public class ChatServerInitializer extends ChannelInitializer<SocketChannel> {
    private final ChatMessageRepository chatMessageRepository;

    // 构造函数：接收 ChatMessageRepository
    public ChatServerInitializer(ChatMessageRepository chatMessageRepository) {
        this.chatMessageRepository = chatMessageRepository;
    }

    @Override
    protected void initChannel(SocketChannel ch) {
        // 添加处理器并传递 Repository
        ch.pipeline().addLast(new ChatServerHandler(chatMessageRepository));
    }
}